﻿using System;
using System.Collections.Generic;
using Opo.Net.Mail;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Moq;

namespace Opo.Perspective.Core
{
    [TestFixture(Description = "Tests for Opo.Perspective.Core.Contact")]
    public class ContactTests
    {
        string _type;
        string _firstName;
        string _lastName;
        string _street;
        string _postalCode;
        string _cityName;
        string _email;
        string _phoneNumber;

        IContactInfo _contactInfo;

        [TestFixtureSetUp]
        public void Setup()
        {
            _type = "Home";
            _firstName = "FirstName";
            _lastName = "LastName";
            _street = "Street";
            _postalCode = "12345";
            _cityName = "City";
            _email = "email@example.org";
            _phoneNumber = "1234567890";

            _contactInfo = new ContactInfo()
            {
                Type = _type,
                Street = _street,
                City = new CityInfo() { Name = _cityName, PostalCode = _postalCode },
                MailAddresses = new MailAddressCollection() { new MailAddress(_email) },
                PhoneNumbers = new PhoneNumberCollection() { new PhoneNumber(_phoneNumber, _type) }
            };
        }

        [TestFixtureTearDown]
        public void Teardown()
        {

        }

        [Test]
        public void CanCreateContactInfo()
        {
            Contact contact = new Contact(_firstName, _lastName, new ContactInfoCollection() { _contactInfo });
            Assert.That(contact.FirstName, Is.EqualTo(_firstName));
            Assert.That(contact.LastName, Is.EqualTo(_lastName));
            Assert.That(contact.ContactInfo[0].Type, Is.EqualTo(_type));
            Assert.That(contact.ContactInfo[0].Street, Is.EqualTo(_street));
            Assert.That(contact.ContactInfo[0].City.Name, Is.EqualTo(_cityName));
            Assert.That(contact.ContactInfo[0].City.PostalCode, Is.EqualTo(_postalCode));
            Assert.That(contact.ContactInfo[0].MailAddresses[0].Address, Is.EqualTo(_email));
            Assert.That(contact.ContactInfo[0].PhoneNumbers[0].Type, Is.EqualTo(_type));
            Assert.That(contact.ContactInfo[0].PhoneNumbers[0].Number, Is.EqualTo(_phoneNumber));
        }

        [Test]
        public void CanCreateContactInfoWithFirstAndLastNameOnly()
        {
            Contact contact = new Contact(_firstName, _lastName);
            Assert.That(contact.FirstName, Is.EqualTo(_firstName));
            Assert.That(contact.LastName, Is.EqualTo(_lastName));
        }
    }
}
